package com.nettest.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

import org.apache.struts2.json.annotations.JSON;

@MappedSuperclass
public abstract class BaseAuditable implements BaseEntity {
	private static final long serialVersionUID = 102360772455032231L;
	@Column(name = "created_by",length=20)
	private String createdBy;
	@Column(name = "created_date")
	@Temporal(value=TemporalType.TIMESTAMP)
	private Date createdDate;
	@Column(name = "updated_by",length=20)
	private String updatedBy;
	@Column(name = "updated_date")
	@Temporal(value=TemporalType.TIMESTAMP)
	private Date updatedDate;
	@Column(name = "version")
	@Version
	private Long version;

	@JSON(serialize=false)
	public String getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}
	@JSON(serialize=true)
	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}
	@JSON(serialize=false)
	public String getUpdatedBy() {
		return updatedBy;
	}

	public void setUpdatedBy(String updatedBy) {
		this.updatedBy = updatedBy;
	}
	@JSON(serialize=false)
	public Date getUpdatedDate() {
		return updatedDate;
	}

	public void setUpdatedDate(Date updatedDate) {
		this.updatedDate = updatedDate;
	}
	@JSON(serialize=false)
	public Long getVersion() {
		return version;
	}

	public void setVersion(Long version) {
		this.version = version;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((this.getId() == null) ? 0 : this.getId().hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if(!(obj instanceof BaseAuditable))
			return false;
		BaseAuditable other = (BaseAuditable) obj;
		if (this.getId() == null) {
			if (other.getId() != null)
				return false;
		} else if (!this.getId().equals(other.getId()))
			return false;
		return true;
	}
}